package com.zhoug.android.recyclerview;

import android.view.View;
import android.view.ViewGroup;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import androidx.annotation.IntDef;

import static java.lang.annotation.RetentionPolicy.SOURCE;

/**
 * @Author 35574
 * @Date 2021/3/3
 * @Description
 */
public abstract class LoadMoreView {
    public static final int IDLE = 0;//初始状态
    public static final int LOADING = 1;//正在加载
    public static final int SUCCESS = 2;//加载成功
    public static final int FAIL = 3;//加载失败
    public static final int END = 4;//没有更多数据了
    public static final int END_GONE = 401;//没有更多数据了,隐藏提示


    @IntDef({IDLE, LOADING, SUCCESS, FAIL, END,END_GONE})
    @Retention(SOURCE)
    @Target({ElementType.FIELD, ElementType.PARAMETER})
    public @interface Status {
    }

    /**
     * 当前状态
     */
    private @Status
    int mStatus = IDLE;


    /**
     *
     * @param parent
     * @return
     */
    protected abstract  View getLoadMoeView(ViewGroup parent);

    /**
     * 初始状态
     */
    protected abstract void onIdle() ;

    /**
     * 正在加载
     */
    protected abstract void onLoading() ;

    /**
     * 加载成功
     */
    protected abstract void onSuccess() ;

    /**
     * 加载失败
     */
    protected abstract void onFail();

    /**
     * 没有更多数据了
     */
    protected abstract void onEnd();


    /**
     * 设置状态
     *
     * @param status
     */
    public void setStatus(@Status int status) {
        this.mStatus = status;
        refreshView();
    }

    public int getStatus() {
        return mStatus;
    }


    /**
     * 刷新
     */
    public void refreshView() {
        switch (mStatus) {
            case IDLE:
                onIdle();
                break;
            case LOADING:
                onLoading();
                break;
            case SUCCESS:
                onSuccess();
                break;
            case FAIL:
                onFail();
                break;
            case END:
            case END_GONE:
                onEnd();
                break;
        }
    }


}
